package cc.rengu.redp.flowable.service;

import cc.rengu.redp.common.domain.QueryRequest;
import cc.rengu.redp.common.exception.RedpException;
import cc.rengu.redp.flowable.domain.ApplyFormEntrance;
import com.alibaba.fastjson.JSONObject;
import com.google.common.io.ByteStreams;

import java.util.List;
import java.util.Map;

public interface ProcessService {

    /**
     * 获取可用的申请列表
     * @param userId
     * @return Map<String, Object>
     */
    List<ApplyFormEntrance> getAvailableProcess(String userId);

    /**
     * 获取可用的申请列表 (仅返回设置了系统启动的流程）
     * @return Map<String, String> key: procDefId, value:procName
     */
    Map<String, String> getAvailableProcess();

    /**
     * 获取待办事项
     * @param userId
     * @param queryText
     * @return Map<String, Object>
     */
    Map<String, Object> getWaitingToDo(String userId, String queryText, QueryRequest queryRequest);

    /**
     * 获取业务数据
     * @param procInstId
     * @return String
     */
    Map<String, Object> getFlowData(String procInstId);

    /**
     * 获取可选分支列表
     * @param taskId
     * @return List<NextToDo> Map<String, Object>
     */
    Map<String, Object> getNextToDo(String taskId);

    /**
     * 启动流程
     * @param flowData
     * @param processDefinitionKey
     * @param applicant
     */
    void launch(String flowData, String processDefinitionKey, String applicant, String nextAssignee) throws RedpException;

    /**
     * 选择分支完成任务
     * @param taskId
     * @param comment
     * @param flowData
     */
    void completeTask(String taskId,
                      String flowStatus,
                      String procInstId,
                      String comment,
                      String flowData,
                      String applicant,
                      String nextAssignee) throws RedpException;

    void completeReceiveTask(String procInstId, JSONObject newFlowData);

    /**
     * 获取历史路径
     * @param procInstId
     * @return
     */
    Map<String, Object> getHisActivities(String procInstId);

    /**
     * 任务单列表查询
     * @param procDefName
     * @param applicant
     * @param procStatus
     * @param queryRequest
     * @return
     */
    Map<String, Object> getAllProcInstances(String procDefName, String applicant, String procStatus, QueryRequest queryRequest);

    /**
     * 查看发布流程图
     * @param procDefId
     * @return ByteStreams
     */
    ByteStreams getProcGraphic(String procDefId);

    /**
     * 强制终止流程
     * @param procInstId
     */
    void terminateProcess(String procInstId);

    /**
     * 预先获取当前选择分支的目标节点所属的用户列表
     * @param sequenceId
     * @param taskId
     * @return
     */
    Map<String, Object> getCandidateUsersPrevious(String sequenceId, String taskId);
    Map<String, Object> getCandidateUsersPrevious(String procDefKey);

    /**
     * 获取在途申请单
     * @param userId
     * @param queryText
     * @return Map<String, Object>
     */
    Map<String, Object> getInTransitProcess(String userId, String queryText, QueryRequest queryRequest);

    /**
     * 获取结束得申请单
     * @param userId
     * @param queryText
     * @return Map<String, Object>
     */
    Map<String, Object> getLatelyClosedProcess(String userId, String queryText, QueryRequest queryRequest);
}
